package com.cos.es.util;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * es的客户端工具类
 */
public class ESClient {
    /**
     * 获取操作es使用的客户端api对象
     * @return
     */
    public static RestHighLevelClient getClient(){
        //HttpHost 用于建立服务器主机连接使用的,需要要提供ip和端口
        HttpHost host = new HttpHost("10.36.137.176", 9200);
        //RestClientBuilder 创建工厂
        RestClientBuilder builder = RestClient.builder(host);
        //RestHighLevelClient es的客户端api对象
        RestHighLevelClient client = new RestHighLevelClient(builder);
        return client;
    }

}
